/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package wli.java.db;

import java.util.List;
import org.hibernate.Query;
import org.hibernate.classic.Session;

/**
 *
 * @author liw
 */
public class AssetHelper {

    Session session = null;

    public AssetHelper() {
        this.session = HibernateUtil.getSessionFactory().getCurrentSession();
    }

    public List getAssetList() {
        List<Asset> assetList = null;
        try {
            org.hibernate.Transaction tx = session.beginTransaction();
            Query q = session.createQuery("from Asset");
            assetList = (List<Asset>) q.list();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return assetList;
    }

    public List getAssetList(int asset_id) {

        List<Asset> assetList = null;
        try {
            org.hibernate.Transaction tx = session.beginTransaction();
            Query q = session.createQuery("from Asset as as where as.asset_id=" + asset_id);
            assetList = (List<Asset>) q.list();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return assetList;
    }

    public List getTargetList(String host_name) {
        //System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>AAAAAAAAAAAA>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");

        List<Target> list = null;
        try {
            org.hibernate.Transaction tx = session.beginTransaction();
            Query q = session.createQuery("from Target as targ where targ.id.assetId='" + host_name + "'");
            list = (List<Target>) q.list();
        } catch (Exception e) {
            e.printStackTrace();
        }

        //System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>BBBBBBBBBBBB>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");

        return list;
    }

    public List getTargetListByFindingId(String finding_id) {
        System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>AAAAAAAAAAAA>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");

        List<Target> list = null;
        try {
            org.hibernate.Transaction tx = session.beginTransaction();
            Query q = session.createQuery("from Target as targ where targ.id.findingId='" + finding_id + "'");
            list = (List<Target>) q.list();
        } catch (Exception e) {
            e.printStackTrace();
        }

        System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>BBBBBBBBBBBB>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");

        return list;
    }
}
